<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<!-- 引入样式 -->
		<link rel="stylesheet" href="../../plugins/elementui/index.css">
		<link rel="stylesheet" href="../../plugins/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="../../css/style.css">
		<!-- 引入组件库 -->
		<script src="../../js/vue.js"></script>
		<script src="../../plugins/elementui/index.js"></script>
		<script type="text/javascript" src="../../js/jquery.min.js"></script>
		<script src="../../js/axios-0.18.0.js"></script>
	</head>
	<body>
		<div id="app" class="app">
			<div class="modal fade in" id="modalBasic_4" tabindex="-1" role="dialog" aria-labelledby="modalBasicLabel" aria-hidden="false">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
							<h4 class="modal-title" id="modalBasicLabel_4">上传文件封面</h4>
						</div>
						<div class="modal-body">
							<label>图片</label>
							<img src="" alt="" id="img" />
							<input type="file" name="file" id="uploadImage" onchange="postData()">
						</div>
						<div class="modal-footer" style='margin-top:20px;'>
							<button type="button" class="btn btn-default cancle" data-dismiss="modal">取 消</button>
							<button id="sure_upload" type="button" class="btn btn-primary sure">上 传</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	 <script type="text/javascript">
	        function postData() {
	            var formData = new FormData();
				var noteId = sessionStorage.getItem("noteId");
				console.log("noteId===="+noteId);
	            formData.append("imgFilename", $("#uploadImage")[0].files[0]);
	            $.ajax({
					async : false,
	                url:"http://localhost:82/setmeal/upload.do",
	                type: "post",
	                data: formData,
	                processData: false, // 告诉jQuery不要去处理发送的数据
	                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
	                dataType: 'json',
	                success: function(data) {
						// console.log(data);
						var params = "http://qr4k8o67g.hn-bkt.clouddn.com/"+data.data;
						$.ajax({
							async : false,
							url:base_path+"/note/uploadNoteCover.do",
							type:"post",
							data:{"noteId":noteId,"params":params},
							dataType:'json',
							success:function(data){
							 if(data.status==0){
								 console.log(data);
								 alert("封面更新成功");
							 }
							},
							error:function(data){
								console.log(data);
							 	alert("封面更新失败");
							}
						});
	                },
	                error: function(data) {
	                    alert("图片上传失败")
	                }
	            });
	        }
	        //赋值变量
	        var basePath = getContextPath();
	        // 获取项目路径
	        function getContextPath() {
	            var pathName = window.document.location.pathname;
	            var projectName = pathName.substring(0, pathName.substr(1).indexOf(
	                '/') + 1);
	            return projectName;
	        }
			
			//获取url中的参数
			function getUrlParam(name) {
			  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			  var r = window.location.search.substr(1).match(reg);  //匹配目标参数
			  if (r != null) return unescape(r[2]); return null; //返回参数值
			};
			
	    </script>
</html>